<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绿能充 - 账户充值</title>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        :root {
            --primary-color: #00a896;
            --secondary-color: #02c39a;
            --dark-color: #05668d;
            --light-color: #f0f3bd;
            --accent-color: #028090;
            --text-dark: #333;
            --text-light: #f8f9fa;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Noto Sans SC', sans-serif;
            color: var(--text-dark);
            background-color: #f9f9f9;
            min-height: 100vh;
            display: flex;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 250px;
            background: linear-gradient(135deg, var(--dark-color) 0%, var(--primary-color) 100%);
            color: white;
            padding: 20px 0;
            height: 100vh;
            position: fixed;
            box-shadow: var(--shadow);
            z-index: 100;
        }

        .sidebar-header {
            padding: 0 20px 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 20px;
        }

        .sidebar-header .logo {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }

        .sidebar-header .logo-icon {
            width: 40px;
            height: 40px;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 18px;
            color: var(--light-color);
        }

        .sidebar-header h3 {
            font-size: 1.2rem;
            font-weight: 500;
            margin: 0;
        }

        .sidebar-header p {
            font-size: 0.8rem;
            opacity: 0.8;
            margin: 0;
        }

        .nav-menu {
            list-style: none;
            padding: 0 15px;
        }

        .nav-item {
            margin-bottom: 5px;
        }

        .nav-link {
            display: flex;
            align-items: center;
            padding: 12px 15px;
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            border-radius: 8px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.1);
            color: white;
        }

        .nav-link i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 16px;
        }

        .nav-link .badge {
            margin-left: auto;
            background-color: var(--light-color);
            color: var(--dark-color);
            font-size: 0.7rem;
            padding: 3px 6px;
        }

        .user-profile {
            position: absolute;
            bottom: 20px;
            left: 0;
            width: 100%;
            padding: 0 20px;
        }

        .user-info {
            display: flex;
            align-items: center;
            padding: 10px;
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            cursor: pointer;
            transition: var(--transition);
        }

        .user-info:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }

        .user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 14px;
        }

        .user-name {
            font-size: 0.9rem;
            font-weight: 500;
            margin-bottom: 2px;
        }

        .user-role {
            font-size: 0.7rem;
            opacity: 0.8;
        }

        /* 主内容区样式 */
        .main-content {
            flex: 1;
            margin-left: 250px;
            padding: 30px;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
        }

        .page-title h1 {
            font-size: 1.8rem;
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 5px;
        }

        .page-title p {
            color: #777;
            font-size: 0.9rem;
            margin: 0;
        }

        .header-actions {
            display: flex;
            gap: 10px;
        }

        .btn {
            padding: 8px 16px;
            border-radius: 8px;
            font-size: 0.9rem;
            font-weight: 500;
            border: none;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
        }

        .btn i {
            margin-right: 6px;
        }

        .btn-primary {
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            box-shadow: 0 4px 15px rgba(0, 168, 150, 0.3);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 168, 150, 0.4);
        }

        .btn-outline {
            background: transparent;
            border: 1px solid #ddd;
            color: #555;
        }

        /* 主内容区样式 - 与主页一致 */
        .main-content {
            flex: 1;
            margin-left: 250px;
            padding: 30px;
            min-height: 100vh;
            background-color: #f5f7fa;
        }

        /* 头部样式 - 与主页一致 */
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            background-color: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: var(--shadow);
        }

        .page-title h1 {
            font-size: 1.8rem;
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 5px;
        }

        .page-title p {
            color: #777;
            font-size: 0.9rem;
            margin: 0;
        }

        /* 充值卡片样式 */
        .recharge-container {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 20px;
            margin-bottom: 30px;
        }

        @media (max-width: 992px) {
            .recharge-container {
                grid-template-columns: 1fr;
            }
        }

        .recharge-card {
            background-color: white;
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 25px;
            transition: var(--transition);
        }

        .recharge-card:hover {
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .card-header h2 {
            font-size: 1.4rem;
            font-weight: 600;
            margin: 0;
            color: var(--dark-color);
        }

        /* 金额选择样式 */
        .amount-options {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 15px;
            margin-bottom: 25px;
        }

        @media (max-width: 576px) {
            .amount-options {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        .amount-option {
            border: 2px solid #ddd;
            border-radius: 8px;
            padding: 15px;
            text-align: center;
            cursor: pointer;
            transition: var(--transition);
        }

        .amount-option:hover {
            border-color: var(--primary-color);
        }

        .amount-option.selected {
            border-color: var(--primary-color);
            background-color: rgba(0, 168, 150, 0.05);
        }

        .amount-option .amount {
            font-size: 1.2rem;
            font-weight: 600;
            color: var(--dark-color);
        }

        .amount-option .bonus {
            font-size: 0.8rem;
            color: #00a896;
            margin-top: 5px;
        }

        /* 自定义金额输入 */
        .custom-amount {
            margin-bottom: 25px;
        }

        .custom-amount label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }

        .amount-input {
            position: relative;
        }

        .amount-input span {
            position: absolute;
            left: 12px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 1rem;
            color: #555;
        }

        .amount-input input {
            width: 100%;
            padding: 12px 12px 12px 30px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 1rem;
            transition: var(--transition);
        }

        .amount-input input:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 2px rgba(0, 168, 150, 0.2);
        }

        /* 支付方式选择 */
        .payment-methods {
            margin-bottom: 25px;
        }

        .payment-method {
            display: flex;
            align-items: center;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 8px;
            margin-bottom: 10px;
            cursor: pointer;
            transition: var(--transition);
        }

        .payment-method:hover {
            border-color: var(--primary-color);
        }

        .payment-method.selected {
            border-color: var(--primary-color);
            background-color: rgba(0, 168, 150, 0.05);
        }

        .payment-method-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: #f5f5f5;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            color: var(--primary-color);
            font-size: 18px;
        }

        .payment-method-info {
            flex: 1;
        }

        .payment-method-name {
            font-weight: 500;
            margin-bottom: 3px;
        }

        .payment-method-desc {
            font-size: 0.8rem;
            color: #777;
        }

        /* 按钮样式 - 与主页一致 */
        .btn {
            padding: 12px 24px;
            border-radius: 8px;
            font-size: 1rem;
            font-weight: 500;
            border: none;
            cursor: pointer;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }

        .btn i {
            margin-right: 8px;
        }

        .btn-primary {
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            box-shadow: 0 4px 15px rgba(0, 168, 150, 0.3);
            width: 100%;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 168, 150, 0.4);
        }

        .btn-outline {
            background: transparent;
            border: 1px solid #ddd;
            color: #555;
            width: 100%;
        }

        .btn-outline:hover {
            background-color: #f5f5f5;
        }

        /* 账户信息卡片 */
        .account-card {
            background: linear-gradient(135deg, var(--dark-color) 0%, var(--primary-color) 100%);
            color: white;
            border-radius: 12px;
            padding: 25px;
            box-shadow: var(--shadow);
            height: 100%;
        }

        .account-card h3 {
            font-size: 1.2rem;
            margin-bottom: 20px;
            font-weight: 500;
        }

        .account-balance {
            font-size: 2.5rem;
            font-weight: 600;
            margin: 20px 0;
            text-align: center;
        }

        .account-details {
            margin-top: 30px;
        }

        .detail-item {
            display: flex;
            justify-content: space-between;
            padding: 10px 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .detail-item:last-child {
            border-bottom: none;
        }

        .detail-label {
            color: rgba(255, 255, 255, 0.8);
        }

        .detail-value {
            font-weight: 500;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .main-content {
                padding: 20px;
            }

            .header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }
        }

        @media (max-width: 576px) {
            .amount-options {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
<!-- 侧边导航栏 - 与主页一致 -->
<div class="sidebar">
    <div class="sidebar-header">
        <div class="logo">
            <div class="logo-icon">
                <i class="fas fa-charging-station"></i>
            </div>
            <div>
                <h3>绿能充</h3>
                <p>用户面板</p>
            </div>
        </div>
    </div>

    <ul class="nav-menu">
        <li class="nav-item">
            <a href="/user/home" class="nav-link">
                <i class="fas fa-tachometer-alt"></i>
                <span>仪表盘</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/announcement/list" class="nav-link">
                <i class="fas fa-bullhorn"></i>
                <span>公告栏</span>
                <span class="badge">5</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/pile/list" class="nav-link">
                <i class="fas fa-charging-station"></i>
                <span>充电桩</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/map/mapDetail" class="nav-link">
                <i class="fas fa-map-marked-alt"></i>
                <span>地图</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/center/personCenter/${user.id}" class="nav-link">
                <i class="fas fa-user-circle"></i>
                <span>个人中心</span>
            </a>
        </li>
    </ul>

    <div class="user-profile">
        <div class="user-info">
            <div class="user-avatar">
                <c:choose>
                    <c:when test="${not empty user.avatar}">
                        <img src="${user.avatar}" alt="用户头像" style="width:100%;height:100%;border-radius:50%;object-fit:cover;">
                    </c:when>
                    <c:otherwise>
                        <i class="fas fa-user"></i>
                    </c:otherwise>
                </c:choose>
            </div>
            <div>
                <div class="user-name">${user.username}</div>
                <div class="user-role">
                    <c:choose>
                        <c:when test="${user.role == 1}">管理员</c:when>
                        <c:when test="${user.role == 2}">测试员</c:when>
                        <c:otherwise>普通用户</c:otherwise>
                    </c:choose>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 主内容区 -->
<div class="main-content">
    <div class="header">
        <div class="page-title">
            <h1>账户充值</h1>
            <p>为您的账户充值余额，享受便捷充电服务</p>
        </div>
        <div class="header-actions">
            <button class="btn btn-outline" onclick="location.href='/user/center/transactions'">
                <i class="fas fa-list"></i> 交易记录
            </button>
        </div>
    </div>

    <div class="recharge-container">
        <!-- 充值表单 -->
        <div class="recharge-card">
            <div class="card-header">
                <h2>选择充值金额</h2>
            </div>

            <form id="rechargeForm" action="${pageContext.request.contextPath}/user/balance/add" method="post">
                <!-- 金额选项 -->
                <div class="amount-options">
                    <div class="amount-option" data-amount="50">
                        <div class="amount">¥50</div>
                        <div class="bonus">无优惠</div>
                    </div>
                    <div class="amount-option" data-amount="100">
                        <div class="amount">¥100</div>
                        <div class="bonus">送¥5</div>
                    </div>
                    <div class="amount-option" data-amount="200">
                        <div class="amount">¥200</div>
                        <div class="bonus">送¥15</div>
                    </div>
                    <div class="amount-option" data-amount="300">
                        <div class="amount">¥300</div>
                        <div class="bonus">送¥30</div>
                    </div>
                    <div class="amount-option" data-amount="500">
                        <div class="amount">¥500</div>
                        <div class="bonus">送¥60</div>
                    </div>
                    <div class="amount-option" data-amount="1000">
                        <div class="amount">¥1000</div>
                        <div class="bonus">送¥150</div>
                    </div>
                </div>

                <!-- 自定义金额 -->
                <div class="custom-amount">
                    <label for="customAmount">或输入其他金额</label>
                    <div class="amount-input">
                        <span>¥</span>
                        <input type="number" id="customAmount" name="amount" min="10" max="10000"
                               placeholder="请输入10-10000之间的整数" required>
                    </div>
                </div>

                <!-- 支付方式 -->
                <div class="payment-methods">
                    <div class="card-header">
                        <h2>选择支付方式</h2>
                    </div>

                    <div class="payment-method selected" data-method="ALIPAY">
                        <div class="payment-method-icon">
                            <i class="fab fa-alipay"></i>
                        </div>
                        <div class="payment-method-info">
                            <div class="payment-method-name">支付宝</div>
                            <div class="payment-method-desc">推荐支付宝用户使用</div>
                        </div>
                    </div>

                    <div class="payment-method" data-method="WECHAT">
                        <div class="payment-method-icon">
                            <i class="fab fa-weixin"></i>
                        </div>
                        <div class="payment-method-info">
                            <div class="payment-method-name">微信支付</div>
                            <div class="payment-method-desc">推荐微信用户使用</div>
                        </div>
                    </div>

                    <div class="payment-method" data-method="BALANCE">
                        <div class="payment-method-icon">
                            <i class="fas fa-wallet"></i>
                        </div>
                        <div class="payment-method-info">
                            <div class="payment-method-name">账户余额</div>
                            <div class="payment-method-desc">使用账户现有余额支付</div>
                        </div>
                    </div>

                    <input type="hidden" id="paymentMethod" name="paymentMethod" value="ALIPAY">
                </div>

                <!-- 提交按钮 -->
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-credit-card"></i>
                    立即充值
                </button>
            </form>
        </div>

        <!-- 账户信息 -->
        <div class="account-card">
            <h3>账户信息</h3>
            <div class="account-balance">
                ¥<fmt:formatNumber value="${user.balance}" pattern="#,##0.00" />
            </div>
            <p style="text-align: center; opacity: 0.8;">当前可用余额</p>

            <div class="account-details">
                <div class="detail-item">
                    <span class="detail-label">用户ID</span>
                    <span class="detail-value">${user.id}</span>
                </div>
                <div class="detail-item">
                    <span class="detail-label">用户名</span>
                    <span class="detail-value">${user.username}</span>
                </div>
                <div class="detail-item">
                    <span class="detail-label">最后充值</span>
                    <span class="detail-value">
                        <c:choose>
                            <c:when test="${not empty lastRecharge}">
                                <fmt:formatDate value="${lastRecharge.paymentTime}" pattern="yyyy-MM-dd" />
                            </c:when>
                            <c:otherwise>
                                暂无记录
                            </c:otherwise>
                        </c:choose>
                    </span>
                </div>
                <div class="detail-item">
                    <span class="detail-label">充值总额</span>
                    <span class="detail-value">
                        ¥<fmt:formatNumber value="${not empty totalRecharge ? totalRecharge : 0}" pattern="#,##0.00" />
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 金额选项选择
        const amountOptions = document.querySelectorAll('.amount-option');
        const customAmountInput = document.getElementById('customAmount');

        amountOptions.forEach(option => {
            option.addEventListener('click', function() {
                // 移除所有选中状态
                amountOptions.forEach(opt => opt.classList.remove('selected'));

                // 添加当前选中状态
                this.classList.add('selected');

                // 设置金额到表单
                const amount = this.getAttribute('data-amount');
                customAmountInput.value = amount;
            });
        });

        // 自定义金额输入时取消选项选择
        customAmountInput.addEventListener('input', function() {
            amountOptions.forEach(opt => opt.classList.remove('selected'));
        });

        // 支付方式选择
        const paymentMethods = document.querySelectorAll('.payment-method');
        const paymentMethodInput = document.getElementById('paymentMethod');

        paymentMethods.forEach(method => {
            method.addEventListener('click', function() {
                // 移除所有选中状态
                paymentMethods.forEach(m => m.classList.remove('selected'));

                // 添加当前选中状态
                this.classList.add('selected');

                // 设置支付方式到表单
                const method = this.getAttribute('data-method');
                paymentMethodInput.value = method;
            });
        });

        // 表单提交验证
        const rechargeForm = document.getElementById('rechargeForm');
        rechargeForm.addEventListener('submit', function(e) {
            const amount = customAmountInput.value;

            if (!amount || amount < 10 || amount > 10000) {
                e.preventDefault();
                alert('请输入10-10000之间的有效金额');
                customAmountInput.focus();
            }
        });

        // 侧边栏当前菜单高亮
        const currentPath = window.location.pathname;
        document.querySelectorAll('.nav-link').forEach(link => {
            if (link.getAttribute('href') === currentPath) {
                link.classList.add('active');
            } else {
                link.classList.remove('active');
            }
        });
    });
</script>
</body>
</html>